package com.tmzn.queue;

import com.alibaba.fastjson2.JSONObject;
import com.tmzn.service.ITDevicePlanService;
import com.tmzn.util.HutoolHttpUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

@Component
@Slf4j
public class MsgQueue extends Thread implements ApplicationRunner {

    private BlockingQueue<String> queue = new ArrayBlockingQueue(1024);


    @Autowired
    private TaskRunner taskRunner;
    public void add(String object){
        try {
            queue.put(object);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void run() {
       while (true){
           try {
               String take = queue.take();
                taskRunner.handlerMsg(take);
           } catch (Exception e) {
               e.printStackTrace();
               log.error("执行异常",e);
           }
       }
    }


    @Override
    public void run(ApplicationArguments args) throws Exception {
            this.start();
            log.info("处理器启动");
    }
}
